/*
  gmpi.h
  Description: MPI
  Created: 2009.10.26
  Version: 1.0
*/

#ifndef __GMPI_H__
#define __GMPI_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "gigione.h"

#define TIMEOUT_TASK_CLOSE 1000

#ifdef WINDOWS
#pragma pack (push, 2)
#endif

#define GIGI_TASK_BLOCK_DEF_SIZE\
  GIGI_COUNT_OF( ((struct gmpi_block_t*)(0))->_nodes)

typedef struct gmpi_block_t
{
  int      _count;                  // count ==0 mean this is Proxy Task
  GIGI_ID  _mpi_id;
  int      _id;
  char     _name[32];
  GIGI_ID  _nodes[32];
}
#ifndef WINDOWS
__attribute__ ((__packed__))
#endif
gmpi_block;

#ifdef WINDOWS
#pragma pack (pop)
#endif

#define gmpi_block_new(size) (gmpi_block*)                          \
malloc ( sizeof (gmpi_block) + ( (size) <= GIGI_TASK_BLOCK_DEF_SIZE \
         ? 0                                                        \
     : ( (size) - GIGI_TASK_BLOCK_DEF_SIZE) * sizeof (GIGI_ID)))

#define gmpi_block_size\
  (sizeof (gmpi_block) - sizeof (GIGI_ID) * GIGI_TASK_BLOCK_DEF_SIZE )


typedef struct gmpi_node_t
{
  GIGI_SOCKET _fd;
  GIGI_ID     _node_id;
}gmpi_node;

struct gigi_mpi_context_t
{
  GIGIONE          _context;               /*   */
  GIGI_SERVICE     _service;          /*   */
  GIGI_SOCKET      _master;           /*   */
  GMPI_FUNC_DEF    _mpi_func;         /*   */
  GIGI_ID          _mpi_id;
  int              _size;
  gmpi_node *      _nodes;
  int              _error_code;
  int              _id;
};

#ifdef __cplusplus
}
#endif

#endif


